<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"/>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="misapplication-tap-highlight" content="no"/>
		<meta name="HandheldFriendly" content="true"/>
		<meta name="MobileOptimized" content="320"/>
		<title>搜班</title>
		<script src="js/mui.min.js"></script>
		<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
		<script type="text/javascript" src="js/common.js"></script>
		<script type="text/javascript" src="js/update.js"></script>
		<script type="text/javascript" src="js/index.js"></script>
		<script type="text/javascript" charset="utf-8">
		mui.plusReady(function() {
			var user_id = plus.storage.getItem('user_id');
			var username = plus.storage.getItem('username');
			var phone = plus.storage.getItem('phone');
			var images = plus.storage.getItem('image');
			//获取用户信息
			document.getElementById("user_user").innerHTML = "";
			var ClassNameHtml = "";
			ClassNameHtml='<div id="headImgDiv"><img id="loge_userImage" class="mui-media-object mui-pull-left" src="'+getServerIp+'/Public/Uploads/image/user/'+images+'"></div><div class="mui-media-body">'+
			'<div class="mui-media-body"><p style="color: #000000;font-size: 24px;margin-top: 20px;">'+username+'</p>'+
			'<p style="mtypeargin-top: 20px;font-size: 18px;">'+phone+'</p></div>';
			document.getElementById("user_user").innerHTML = ClassNameHtml;
			
		    document.getElementById('collection').addEventListener('tap', function() {
                mui.openWindow({
                    url: 'plus/Data/myCollection.html', 
                    id:'myCollection',
	                     waiting:{
                            autoShow:false,//自动显示等待框，默认为true
                          }
                });
            });
            
            document.getElementById('community').addEventListener('tap', function() {
                mui.openWindow({
                    url: 'plus/Data/myCommunity.html', 
                    id:'myCommunity',
	                     waiting:{
                            autoShow:false,//自动显示等待框，默认为true
                          }
                });
            });
            
            document.getElementById('order').addEventListener('tap', function() {
                mui.openWindow({
                    url: 'plus/Data/myOrder.html', 
                    id:'myOrder',
	                     waiting:{
                            autoShow:false,//自动显示等待框，默认为true
                          }
                });
            });
            
            document.getElementById('password').addEventListener('tap', function() {
                mui.openWindow({
                    url: 'plus/Data/passwordReset.html', 
                    id:'passwordReset',
                    extras: {
						id:user_id
					},
	                     waiting:{
                            autoShow:false,//自动显示等待框，默认为true
                          }
                });
            });
		  
            //进入首页面
            document.getElementById('indexTab').addEventListener('tap', function() {
                mui.openWindow({
                    url: 'index.html', 
                    id:'index',
	                     waiting:{
                            autoShow:false,//自动显示等待框，默认为true
                          }
                });
            }); 
            //进入社区页面
            document.getElementById('communityTab').addEventListener('tap', function() {
            	mui.openWindow({
                        url: 'community.html', 
                        id:'community',
	                     waiting:{
                            autoShow:false,//自动显示等待框，默认为true
                          }
                   }); 
            	/*var userinfo = plus.storage.getItem('userinfo');
            	if (userinfo != '' && userinfo != null) {
            		mui.openWindow({
                        url: 'community.html', 
                        id:'community',
	                     waiting:{
                            autoShow:false,//自动显示等待框，默认为true
                          }
                   }); 
            	} else{
            		mui.openWindow({
                        url: 'login.html', 
                        id:'login',
	                     waiting:{
                            autoShow:false,//自动显示等待框，默认为true
                          }
                    });
            	}*/
                
            }); 
            
            //进入个人中心页面
            document.getElementById('dataTab').addEventListener('tap', function() {
            	var userinfo = plus.storage.getItem('userinfo');
            	if (userinfo != '' && userinfo != null) {
	                mui.openWindow({
	                    url: 'data.html', 
	                    id:'data',
	                     waiting:{
                            autoShow:false,//自动显示等待框，默认为true
                          }
	                });
            	} else{
            		mui.openWindow({
                        url: 'login.html', 
                        id:'login',
	                     waiting:{
                            autoShow:false,//自动显示等待框，默认为true
                          }
                    });
            	}
            });
            
            document.getElementById('button2').addEventListener('tap', function() {
  //打开关于页面
               if(confirm('确定退出登陆吗？')){
               	plus.storage.setItem('userinfo',"");
				plus.storage.setItem('user_id',"");
				plus.storage.setItem('username',"");
				plus.storage.setItem('phone',"");
				plus.storage.setItem('image',"");
                mui.openWindow({
                    url: 'login.html', 
                    id:'login',
	                     waiting:{
                            autoShow:false,//自动显示等待框，默认为true
                          }
                });}
            });
            
            mui('#' + parent.id).popover('toggle');
 
        });

        // 拍照
function getImage() {
	var user_id = plus.storage.getItem('user_id');
	var cmr = plus.camera.getCamera();
	cmr.captureImage( function ( p ) {
		plus.io.resolveLocalFileSystemURL( p, function ( entry ) {
//			document.getElementById("headImgDiv").innerHTML="<img id='loge_userImage' class='mui-media-object mui-pull-left' src='"+entry.toLocalURL()+"'>";
	        
			//创建一个canvas
		    var c=document.createElement("canvas");
			//设置canvas宽高为图片宽高
			c.width=480;c.height=640;
			//将图片绘制到canvas
			var cxt=c.getContext("2d");
			var img=new Image();
			img.src=entry.toLocalURL();
			
		    img.onload = function (){
                document.getElementById("headImgDiv").innerHTML="<img id='loge_userImage' class='mui-media-object mui-pull-left' style='width: 20vw;height: 20vw;margin-left: 2vw;' src='"+entry.toLocalURL()+"'>";
          
			    cxt.drawImage(img,0,0,480,640);
			    
		        //得到图片的base64编码数据
			    var dd=c.toDataURL('image/png');
			    //log出图片base64数据
			    console.log(dd);
			    //获取base64数据
			    var base64Data = dd.substr(22);
			    console.log(base64Data);
			    mui.ajax({ //ajax请求
					url: getServerIp + 'AppUser/resetImage',
					type: 'POST',
					data: {
						files:dd,id:user_id
					}, //传参
					success: function(data, textStatus, jqXHR) {
						plus.storage.setItem('image',data.image);
						alert(data.msg);
					}
					});
            }
	        
	        $("#picture").hide();
	        $(".mui-backdrop").hide();
	        
	
	//	createItem( entry ); 
		}, function ( e ) {
//		alert( "读取拍照文件错误："+e.message );
		} );
	}, function ( e ) {
//	alert( "失败："+e.message );
	},{filter:"image"} );
}

function galleryImg() {
	var user_id = plus.storage.getItem('user_id');
	// 从相册中选择图片
    plus.gallery.pick( function(path){
    	//alert(path);
	/*mui.ajax({ //ajax请求
					url: getServerIp + 'AppUser/resetImage',
					contentType:"multipart/form-data",
					type: 'POST',
					data: {    
						files:path,id:user_id
					}, //传参
					success: function(data, textStatus, jqXHR) {
						
						alert(data.files);
					}
					});*/
    	//console.log(path);
//  	document.getElementById("headImgDiv").innerHTML="<img id='loge_userImage' class='mui-media-object mui-pull-left' style='width: 20vw;height: 20vw;margin-left: 2vw;' src='"+path+"'>";
	    //创建一个canvas
		    var c=document.createElement("canvas");
			//设置canvas宽高为图片宽高
			c.width=480;c.height=640;
			//将图片绘制到canvas
			var cxt=c.getContext("2d");
			var img=new Image();
			img.src=path;
		    img.onload = function (){
                document.getElementById("headImgDiv").innerHTML="<img id='loge_userImage' class='mui-media-object mui-pull-left' style='width: 20vw;height: 20vw;margin-left: 2vw;' src='"+path+"'>";
          
			    cxt.drawImage(img,0,0,480,640);
			    
		        //得到图片的base64编码数据
			    var dd=c.toDataURL('image/png');
			    //log出图片base64数据
//			    console.log(dd);
			    //获取base64数据
			    var base64Data = dd;//.substr(22)
			    console.log(base64Data);
			    mui.ajax({ //ajax请求
					url: getServerIp + 'AppUser/resetImage',
					type: 'POST',
					data: {
						files:base64Data,id:user_id
					}, //传参
					success: function(data, textStatus, jqXHR) {
						plus.storage.setItem('image',data.image);
						alert(data.msg);
					}
					});
			}
	    
	    $("#picture").hide();
	    $(".mui-backdrop").hide();
//  	outLine(path);
        //showImg( path );
        //createItem(path);
   }, function ( e ) {
    	outSet( "取消选择图片" );
    }, {filter:"image"} );
}
    
		</script>

		<link rel="stylesheet" href="css/mui.min.css">
		<style>
			html,
			body {
				background-color: #efeff4;
			}
			.mui-bar-nav~.mui-content {
				padding: 0;
			}
			.title {
				margin: 20px 15px 10px;
				color: #6d6d72;
				font-size: 15px;
				padding: 10px 0;
                border-bottom: 1px solid #ddd;
			}
			
			.mui-views,
			.mui-view,
			.mui-pages,
			.mui-page,
			.mui-page-content {
				position: absolute;
				left: 0;
				right: 0;
				top: 0;
				bottom: 0;
				width: 100%;
				height: 100%;
				background-color: #efeff4;
			}
			.mui-scroll-wrapper,
			.mui-scroll {
				background-color: #efeff4;
				top: 20px;
			}
			.mui-pages .mui-page {
				display: block;
			}
			.mui-page .mui-table-view:first-child {
				margin-top: 15px;
			}
			.mui-page .mui-table-view:last-child {
				margin-bottom: 30px;
			}
			.mui-table-view {
				margin-top: 20px;
			}
/*菜单样式*/
.menu{ width: 100%; height: 45px; position: fixed; bottom:0; left:0; box-shadow: #2d2d2d 0 0 4px;background:#0099cc;}
.menu.menucurr{ background: #ea4c88;}
.menu ul{width: 100%; height: 100%; }
.menu li{ width: 24.9%; height: 100%; float: left; line-height: 45px; text-align: center; background: #0099cc; color:#fff;}
.menu li.curr{ background: #ea4c88;}
.menu li:nth-child(1),.menu li:nth-child(2),.menu li:nth-child(3){ border-right:1px solid #663300;}
		</style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<button class="mui-action-back mui-btn mui-btn-blue mui-btn-link mui-btn-nav mui-pull-left">
				<span class="mui-icon mui-icon-left-nav" style="float: left;height: 40px;line-height: 40px;"></span>
				<img src="images/logo.png"  style=" height: 40px;"/>
			</button>
			<h1 class="mui-title">个人中心</h1>
		</header>
		<div class="mui-page-content">
				<div class="mui-scroll-wrapper">
					<div class="mui-scroll">
						<ul class="mui-table-view mui-table-view-chevron">
							<li id="user_user" class="mui-table-view-cell">
								<!--<div id="headImgDiv"><img id="loge_userImage" class="mui-media-object mui-pull-left" src="images/cbd.jpg"></div>
								
						        <div class="mui-media-body">
							        <p style="color: #000000;font-size: 24px;margin-top: 20px;">
							        	<input type="text" id="username" readonly="readonly">
							        </p>
							        <p style="mtypeargin-top: 20px;font-size: 18px;">
							        	<input ="text" id="phone" readonly="readonly">
							        </p>
						        </div>-->
							</li>
						</ul>
						<ul class="mui-table-view mui-table-view-chevron">
							<li class="mui-table-view-cell" id="collection">
								<a class="mui-navigate-right">
								    <span class="mui-icon mui-icon-starhalf" style="color: #00CA75;"></span>	
									我的收藏
								</a>
							</li>
							<li class="mui-table-view-cell" id="community">
								<a class="mui-navigate-right">
									<span class="mui-icon mui-icon-flag" style="color: #00CA75;"></span>
									我的帖子
								</a>
							</li>
							<li class="mui-table-view-cell" id="order">
								<a class="mui-navigate-right">
									<span class="mui-icon mui-icon-paperplane" style="color: #00CA75;"></span>
									我的预约
								</a>
							</li>
						</ul>
						<ul class="mui-table-view mui-table-view-chevron">
							<li class="mui-table-view-cell" id="password">
								<a class="mui-navigate-right">
									<span class="mui-icon mui-icon-locked" style="color: #00CA75;"></span>
									修改密码
								</a>
							</li>
							<li class="mui-table-view-cell" style="height: 47px;">
								<a href="#picture" class="" style="width: 100%;position: absolute;">
									<span class="mui-icon mui-icon-contact" style="color: #00CA75;"></span>
									修改头像
								</a>
							</li>
						</ul>
						<ul class="mui-table-view">
							<li class="mui-table-view-cell" id="button2" style="text-align: center;">
								<a>退出登录</a>
							</li>
						</ul>
					</div>
				</div>
			</div>
		<nav class="mui-bar mui-bar-tab" style="background: #E4E9EA;">
			<a id="indexTab" class="mui-tab-item" href="index.html">
				<span class="mui-icon mui-icon-home"></span>
				<span class="mui-tab-label">首页</span>
			</a>
			<a id="communityTab" class="mui-tab-item" href="community.html">
				<span class="mui-icon mui-icon-pengyouquan"></span>
				<span class="mui-tab-label">社区</span>
			</a>
			<a id="dataTab" class="mui-tab-item mui-active" href="data.html">
				<span class="mui-icon mui-icon-contact"></span>
				<span class="mui-tab-label">我的</span>
			</a>
		</nav>
		
		
		<div id="picture" class="mui-popover mui-popover-action mui-popover-bottom">
			<ul class="mui-table-view">
				<li class="mui-table-view-cell" style="height: 46px;">
					<!--<a onclick="getImage();">拍照上传</a>-->
					<a onclick="getImage()" style="position: absolute;width: 100%;left: 0;" >拍照上传</a>
				</li>
				<li class="mui-table-view-cell" style="height: 46px;">
					<a onclick="galleryImg()" style="position: absolute;width: 100%;left: 0;" >选取现有的</a>
				</li>
			</ul>
			<ul class="mui-table-view">
				<li class="mui-table-view-cell" style="height: 46px;">
					<a href="#picture" style="position: absolute;width: 100%;left: 0;"><b>取消</b></a>
				</li>
			</ul>
		</div>
	</body>

</html>

